package com.example.juc;

import java.util.concurrent.Semaphore;

public class SemaphoreTest {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);
        for (Integer i = 0; i < 6; i++) {
            new Thread(()->{
                try {
                    semaphore.acquire();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("获得停车位"+Thread.currentThread().getName());
                semaphore.release();
            },i.toString()).start();
        }
    }
}
